{extend name="public/base" /}
{block name='body'}
<div class="layui-container">
    <div class="fly-panel" pad20 style="padding-top: 5px;">
        <!--<div class="fly-none">没有权限</div>-->
        <div class="layui-form layui-form-pane">
            <div class="layui-tab layui-tab-brief" lay-filter="user">
                <ul class="layui-tab-title">
                    <li class="layui-this">编辑</li>
                </ul>
                <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
                    <div class="layui-tab-item layui-show">
                        <div class="layui-form">
                            <div class="layui-row layui-col-space15 layui-form-item">
                                <div class="layui-col-md3">
                                    <label class="layui-form-label">所在分类</label>
                                    <div class="layui-input-block">
                                        <select lay-verify="required" name="FK_ResourceCategoryGuid">
                                            <option></option>
                                            {volist name='cats' id='cat'}
                                            {if condition="$res['FK_ResourceCategoryGuid'] eq $cat['PK_ResourceCategoryGuid']"}
                                            <option selected value="{$cat.PK_ResourceCategoryGuid}">{$cat.Name}</option>
                                            {else /}
                                            <option value="{$cat.PK_ResourceCategoryGuid}">{$cat.Name}</option>
                                            {/if}
                                            {/volist}
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-col-md9">
                                    <label for="L_title" class="layui-form-label">标题</label>
                                    <div class="layui-input-block">
                                        <input type="text" id="L_title" name="Title" required lay-verify="required"
                                               autocomplete="off" class="layui-input" value="{$res.Title}">
                                        <!-- <input type="hidden" name="id" value="{{d.edit.id}}"> -->
                                    </div>
                                </div>
                            </div>
                            <div class="layui-row layui-col-space15 layui-form-item" id="LAY_quiz">
                                <div class="layui-col-md4">
                                    <label class="layui-form-label">资源类型</label>
                                    <div class="layui-input-block">
                                        <select name="type" lay-filter="restype">
                                            {volist name='resType' id='rt'}
                                            {if condition='$res.type eq $rt'}
                                            <option selected value="{$rt}">{$rt}</option>
                                            {else /}
                                            <option value="{$rt}">{$rt}</option>
                                            {/if}
                                            {/volist}

                                        </select>
                                    </div>
                                </div>

                                <!--网盘分享开始-->
                                <div class="layui-col-md6 layui-hide pan" title="网盘资源">
                                    <label class="layui-form-label" for="L_version">网盘地址</label>
                                    <div class="layui-input-block">
                                        <input type="text" value="" name="panurl" autocomplete="off"
                                               class="layui-input" placeholder="网盘地址,带http或https的地址">
                                    </div>
                                </div>
                                <div class="layui-col-md2 layui-hide pan" title="网盘资源">
                                    <label class="layui-form-label" for="L_browser">分享密码</label>
                                    <div class="layui-input-block">
                                        <input type="text" id="L_browser" value="" name="panpwd"
                                               placeholder="密码" autocomplete="off"
                                               class="layui-input">
                                    </div>
                                </div>
                                <!--网盘分享结束-->

                                <!--实体资源-->
                                <div class="layui-col-md8 layui-hide pan" title="实体资源">
                                    <button type="button" class="layui-btn" id="test3"><i class="layui-icon"></i>上传文件
                                    </button>
                                </div>

                                <!--URL资源-->
                                <div class="layui-col-md8 layui-hide pan" title="URL资源">
                                    <label class="layui-form-label" for="L_version">URL地址</label>
                                    <div class="layui-input-block">
                                        <input type="text" id="L" value="" name="weburl" autocomplete="off"
                                               class="layui-input" placeholder="请输入完整的url地址">
                                    </div>
                                </div>

                                <!--默认-->
                                <div class="layui-col-md8 pan">
                                    <label class="layui-form-label">值</label>
                                    <div class="layui-input-block">
                                        <input disabled type="text" value="{$res.type_value}" autocomplete="off"
                                               class="layui-input">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item layui-form-text">
                                <div class="layui-input-block">
                                    <textarea id="L_content" name="Desc" required lay-verify="required"
                                              placeholder="详细描述" class="layui-textarea fly-editor"
                                              style="min-height: 380px;max-height: 2000px;">{$res.Desc}</textarea>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">所需金币</label>
                                    <div class="layui-input-inline" style="width: 190px;">
                                        <select name="Price">
                                            {volist name='price' id='p'}
                                            {if condition='$p eq $res.Price'}

                                            <option selected value="{$p}">{$p}</option>
                                            {else /}
                                            <option value="{$p}">{$p}</option>

                                            {/if}

                                            {/volist}`
                                        </select>
                                    </div>
                                    <div class="layui-form-mid layui-word-aux">分享后无法修改金币</div>
                                </div>

                                <!--验证码-->
                                <!-- <div class="layui-form-item">
                                     <label for="L_vercode" class="layui-form-label">验证码</label>
                                     <div class="layui-input-inline">
                                         <input type="text" id="L_vercode" name="vercode" required lay-verify="required"
                                                placeholder="填写验证码" autocomplete="off" class="layui-input">
                                     </div>
                                     <div class="layui-form-mid">
                                         <span style="color: #c00;"><div class="sw-verify-img"><img
                                                 src="{:url('base/vercode')}?id=modifyShare" alt=""
                                                 onclick="this.src=this.src+'&'+Math.random()"></div></span>
                                     </div>
                                 </div>-->

                                <div class="layui-form-item">
                                    <hr>
                                </div>
                                <div class="layui-form-item">
                                    <button class="layui-btn layui-btn-fluid" lay-filter="share" lay-submit>提交修改
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    layui.config(
        {
            base: "__JS__/"
        }
    ).use(['form', 'jquery', 'layer', 'upload', 'res'], function ()
    {
        let form = layui.form;
        let layer = layui.layer;
        let $ = layui.jquery;
        let upload = layui.upload, resopnse = layui.res;
        let fileUrl = '';
        let fileName = '';
        let isFile = false;

        /**
         * 资源类别选择
         */
        form.on('select(restype)', function (data)
        {
            let val = data.value;//当前选中的资源类型的值
            $('.pan').addClass('layui-hide');
            $(".pan[title='" + val + "']").removeClass('layui-hide');
        });


        /**
         * 提交资源
         */
        form.on('submit(share)', function (data)
        {
            let resData = data.field;
//            let type = resData.type;
//            let vercode = resData.vercode;
            if (resData.restype === '实体资源')
            {
                if (!fileUrl) return layer.alert('请上传你的附件');
            }
//            $.post("{:url('base/checkVercode')}", {"code": vercode, "id": "modifyShare"}, function (res) {
//                if (res.errno === 0) {
            //验证码正确
            switch (resData.type)
            {
                case "网盘资源":
                {
                    resData.type_value = resData.panurl + "-" + resData.panpwd;
                }
                    break;
                case "URL资源":
                {
                    resData.type_value = resData.weburl;
                }
                    break;
                case "实体资源":
                {
                    resData.type_value = fileUrl;
                }
            }
            resData['PK_ResourceGuid'] = "{$res.PK_ResourceGuid}";
            $.post("{:url('user/modifyShareApi')}", resData, function (res)
            {
                resopnse.modify(res);
            })
//
//                } else {
//                    //验证码错误
//                    return layer.msg('验证码错误');
//                }
//            });

        })


        /**
         * 文件上传
         */
        upload.render({
            elem: '#upRes'
            , url: "{:url('base/upload')}"
            , size: 10240
            , drag: true
            , accept: 'file'
            , before: function (obj)
            { //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                layer.load('生产者'); //上传loading
                obj.preview(function ()
                {
                    fileName = arguments[1].name;
                });
            }
            , done: function (res, index, upload)
            {
                if (res.errno === 0)
                {
                    fileUrl = res.data;
                }
                layer.closeAll('loading'); //关闭loading
                layer.alert("文件[" + fileName + "] 上传成功");
                $("#fileInfo").html("文件[" + fileName + "]上传成功");
                isFile = true;
            }
            , error: function (index, upload)
            {
                layer.closeAll('loading'); //关闭loading
                layer.msg('系统繁忙,请稍后再试');
            }
        });
    });

</script>
{/block}
